#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    vector<long long> resultArray(vector<int>& nums, int k) {
        vector<long long> ret(k);
        vector<vector<int>> dp(nums.size()+1,vector<int>(k,0));
        for(int i = 0;i<nums.size();i++)
        {
            int v = nums[i];
            dp[i+1][v%k] = 1;
            for(int y = 0;y<k;y++)
            {
                dp[i+1][1ll*y*v%k]+=dp[i][y];
            }
            for(int x = 0;x<k;x++)
            {
                ret[x]+=dp[i+1][x];
            }
        }
        return ret;
    }
};